package com;

import org.junit.Test;

import java.util.Calendar;
import java.util.Scanner;

import java.util.Vector;

/**
 * @author Administration
 * @date 2022/8/5 - 16:35 - 星期五
 * @project lambda
 * @package com
 * @by 晨
 */
public class code {
    @Test
    public void a() {
        for (int i = 1; i <= 4; i++) {
            for (int j = 1; j < i; j++) {
                System.out.print(" ");
            }

            for (int j = 4; j >= i; j--) {
                System.out.print("*");
            }

            for (int j = 3; j >=i; j--) {
                System.out.print("*");
            }
            System.out.println();
        }

        for (int i = 1; i <= 3; i++) {
            for (int j = 3; j > i; j--) {
                System.out.print(" ");
            }

            for (int j = 1; j <=i ; j++) {
                System.out.print("*");
            }

            for (int j = 0; j <=i ; j++) {
                System.out.print("*");
            }

            System.out.println();
        }
    }

    @Test
    public void sb() {
        int[][] array = {{1, 2}, {2, 3}, {3, 4}};
        for (int[] ints : array) {
            System.out.println(ints);
            for (int anInt : ints) {
                System.out.println(anInt);
            }
        }

        System.out.println("----------------------------------------");
        int mytable[][] = {{23, 45, 65, 34, 21, 67, 78},
                {46, 14, 18, 46, 98, 63, 88},
                {98, 81, 64, 90, 21, 14, 23},
                {54, 43, 55, 76, 22, 43, 33}
        };

        int sum, max, maxRow = Integer.MIN_VALUE;
        max = Integer.MIN_VALUE;
        for (int row = 0; row < 4; row++) {
            sum = 0;
            for (int col = 0; col < 7; col++) {
                sum += mytable[row][col];
            }
            if (sum > max) {
                max = sum;
                maxRow = row;
            }
        }
        System.out.println("Row" + maxRow + "MAX" + max);
    }

    @Test
    public void contrary () {
        int field = Calendar.MINUTE;
        int amount = 2;
            Calendar calendar = Calendar.getInstance();
            calendar.add(field, amount);
        long time = calendar.getTime().getTime();
        System.out.println(time);


        int[] b = new int[100];
        for (int i = 0; i < 100; i++) {
            int j = (int) (Math.random() * (100 - 1 + 1)) + 1;
            b[i] = j;
        }
        System.out.println();

    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String next = scanner.next();
        if (next.length() < 2) {
            System.out.println(next);
        }
    }

    @Test
    public void asd () {
        Vector<String> myVector = new Vector<String>(100);
        for (int i = 0; i < 10; i++) {
            myVector.addElement("welcome");
            myVector.addElement("to");
            myVector.addElement("be");
        }

        while (myVector.removeElement("to"));
        for (String s : myVector) {
            System.out.println(s);
        }
    }

    @Test
    public void zxc () {
        char[] a = {'1','2','3','4','5','8',9};
        String s1 = new String(a,2,1);
        String s2 = "JavaWorld!";
        System.out.println(s1);
        System.out.println(s2.indexOf("a"));
        System.out.println(s2.replace("t","r"));
        System.out.println(s2.substring(4,6));
    }

    @Test
    public void aVoid () {
        int[] b = new int[1000];
        for (int i = 0; i < b.length; i++) {
            int math = (int) (Math.random() * ((100 - 1) +1)) +1;
            b[i] = math;
        }

        System.out.println("数组初始化");
        for (int i = 0; i < b.length; i++) {
            System.out.println(b[i]);
        }

        for (int i = 0; i < b.length; i++) {
            int sum = 1;
            for (int j = 0; j < b.length; j++) {
                if (b[j] == b[i]) {
                    sum++;
                }
            }
            System.out.println(b[i] + "数字在数组中出现了" + sum);
        }
    }

    @Test
    public void moveOddFront() {
        int[] a = {1,2,12,4,5,6,7,8,9};

        for (int i = 0; i < a.length-1; i++) {
            for (int j = 0; j < a.length-1-i; j++) {
                if (a[j] % 2 == 0 ) {
                    int tem = a[a.length - 1 - i];
                    a[a.length - 1 - i] = a[j];
                    a[j] = tem;
                }
            }
        }

        for (int i : a) {
            System.out.println(i);
        }
    }

    @Test
    public void bb () {

    }

    @Test
    public void ascendingOrder () {
        int[] b = new int[100];
        for (int i = 0; i <100; i++) {
            int math = (int) (Math.random() * ((1000 - 10) +1)) + 10;
            b[i] = math;
        }
        System.out.println("升序排序前的数组");
        for (int i = 0; i < b.length; i++) {
            System.out.println(b[i])
        ;
    }
        for (int i = 0; i < b.length-1; i++) {
            for (int j = 0; j < b.length-1-i; j++) {
                if (b[j] > b[j+1]) {
                    int temp = b[j + 1];
                    b[j + 1] = b[j];
                    b[j] = temp;
                }
            }
        }

        System.out.println("升序排序后的数组");
        for (int i = 0; i < b.length; i++) {
            System.out.println(b[i]);
        }

        System.out.println("降序排序前的数组");
        for (int i = 0; i < b.length; i++) {
            System.out.println(b[i]);
        }

        for (int i = 0; i < b.length-1; i++) {
            for (int j = 0; j < b.length-1-i; j++) {
                if (b[j] < b[j+1]) {
                    int temp = b[j];
                    b[j] = b[j+1];
                    b[j+1] = temp;
                }
            }
        }

        System.out.println("降序排序后的数组");
        for (int i = 0; i < b.length; i++) {
            System.out.println(b[i]);
        }
    }
}

class PassTest {
    float m;

    void c1 (int pi) {
        pi = 100;
    }

    void c2 (String ps) {
        ps =new String("h");
    }

    void c3 (PassTest passTest) {
        passTest.m = 100.00f;
    }

    public static void main(String[] args) {
        PassTest pt = new PassTest();
        int i = 22;
        pt.c1(i);
        System.out.println(i);

        String s = new String("qwer");
        pt.c2(s);
        System.out.println(s);

        pt.m = 22.0f;
        pt.c3(pt);
        System.out.println(pt.m);
    }
}

class Qangle{
    int a,h;

    Qangle () {
        a = 10;
        h = 20;
    }

    Qangle (int x, int y) {
        a = x;
        h = y;
    }

    Qangle (Qangle r) {
        a = r.width();
        h = r.height();
    }

    int width () {
        return a;
    }

    int height () {
        return h;
    }

    public static void main(String[] args) {
        Qangle q1 = new Qangle();
        Qangle q2 = new Qangle(20,50);
        Qangle q3 = new Qangle(q1);
        System.out.println(q1.width()+""+q1.height());
        System.out.println(q2.width()+""+q2.height());
        System.out.println(q3.width()+""+q3.height());
    }
}

class MyVector extends Vector{
    public MyVector() {
        super(1,1);
    }

    public void addInt (int i) {
        addElement(new Integer(i));
    }

    public void addFloat (float f) {
        addElement(new Float(f));
    }

    public void addString (String s) {
        addElement(new String(s));
    }

    public void addCharArray (char a[]) {
        addElement(a);
    }

    public void printVector () {
        Object o;
        int length = size();
        System.out.println("*******"+length);
        for (int i = 0; i < length; i++) {
            o = elementAt(i);
            if (o instanceof char[]) {
                System.out.println(String.copyValueOf((char[] )o));
            }
            else {
                System.out.println(o.toString());
            }
        }
    }

    public static void main(String[] args) {
        MyVector v = new MyVector();
        int digit = 5;
        float real = 3.14f;
        char le[] = {'a','b','c','d'};
        String s = new String("Hi there !");
        v.addInt(digit);
        v.addFloat(real);
        v.addString(s);
        v.addCharArray(le);
        v.printVector();
    }
}

interface Shape2D{
    final double pi = 3.14;
    double area();
}

class Circle implements Shape2D{

    double radius;

    public Circle (double r){radius = r;}

    @Override
    public double area() {
        return (pi*radius*radius);
    }
}

class Rectangle implements Shape2D{

    int width, height;

    public Rectangle (int x, int y) {
        width =x;
        height =y;
    }
    @Override
    public double area() {
        return (width*height);
    }

    public static void main(String[] args) {
        Rectangle rectangle = new Rectangle(5,6);
        System.out.println(rectangle.area());

        Circle circle = new Circle(2.0);
        System.out.println(circle.area());
    }
}